//
//  NSTimerExtension.swift
//  covermedia
//
//  Created by limao on 16/6/22.
//  Copyright © 2016年 covermedia. All rights reserved.
//

import UIKit

class NSTimerExtension: NSObject {

}

public typealias TimerExecuteClosure = @convention(block)()->()
extension Timer {
    public class func cm_scheduledTimerWithTimeInterval(_ ti:TimeInterval, closure:TimerExecuteClosure, repeats yesOrNo: Bool) -> Timer{
        return self.scheduledTimer(timeInterval: ti, target: self, selector: #selector(Timer.executeTimerClosure(_:)), userInfo: unsafeBitCast(closure, to: AnyObject.self), repeats: true)
    }
    
    public class func executeTimerClosure(_ timer: Timer)
    {
        let closure = unsafeBitCast(timer.userInfo as AnyObject, to: TimerExecuteClosure.self)
        closure()
    }
}
